package main

import "fmt"

func BinarySearch(arr *[]int, item int) bool {
	n := len((*arr))
	start := 0
	end := n-1
	for start <= end{
		mid := (start + end) / 2
		if item < (*arr)[mid]{
			end = mid -1
		}else if item > (*arr)[mid]{
			start = mid +1
		}else {
			return true
		}
	}
	return false
}

//func binaryFind(arr *[]int, left int, right int, item int) bool{
//	if  left > right{
//		return false
//	}
//	mid := (left + right) /2
//	if (*arr)[mid] > item {
//		binaryFind(arr, left, mid-1, item)
//	}else if (*arr)[mid] < item{
//		binaryFind(arr, mid+1, right, item)
//	}else {
//		return true
//	}
//	return false
//}

func main() {
	arr := []int{12, 6, 7, 23, 4, 9, 27, 15, 45}
	res := BinarySearch(&arr, 27)
	//res1 := binaryFind(&arr, 0, len(arr)-1, 27)
	fmt.Println(res)
	//fmt.Println(res1)
}



